var express = require('express');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();
var path = require('path');
/* GET users listing. */
router.get('/', function (req, res, next) {
    var db = new sqlite3.Database(path.join(__dirname, "../db/Delphi.s3db"));
    try {
        sqlStr1 = "UPDATE s_expert SET pwd = ? where s_expert_id = ? and pwd = ?";
        sqlStr2 = "UPDATE p_expert SET pwd = ? where p_expert_id = ? and pwd = ?";
        sqlStr3 = "UPDATE visitor SET pwd = ? where visitor_id = ? and pwd = ?";
        sqlStr4 = "UPDATE admin SET pwd = ? where admin_id = ? and pwd = ?";
        db.all(sqlStr1, [req.query.again_password, req.session.username, req.query.old_password], function (err) {
            if (err != null) {
                db.all(sqlStr2, [req.query.again_password, req.session.username, req.query.old_password], function (err) {
                    if (err != null) {
                        db.all(sqlStr3, [req.query.again_password, req.session.username, req.query.old_password], function (err) {
                            if (err != null) {
                                db.all(sqlStr4, [req.query.again_password, req.session.username, req.query.old_password], function (err) {
                                    if (err != null) {
                                        res.send('0');
                                    } else {
                                        res.send('1');
                                    }
                                });
                            } else {
                                res.send('1');
                            }
                        });
                    } else {
                        res.send('1');
                    }
                });
            } else {
                res.send('1');
            }
        });
    } catch (ex) {
        console.log(ex);
    }
});

module.exports = router;